#include "full.h"
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#include <vector>
#include <iostream>
std::vector<uint8_t> vec;

void find_str(std::vector<uint8_t> &target)
{
    target.clear();
    while (vec.at(0) == '#')
        vec.erase(vec.begin());
    while (vec.at(0) == '*')
    {
        target.push_back(vec.at(0));
        vec.erase(vec.begin());
    }
}

void cb(int id, uint8_t *buffer, int len)
{
    /*uint8_t * mbuf = new uint8_t[255];
    bool flag = false;
    int pmbuf = 0;
    for(int i=0;i<len;i++){
        if(buffer[i] == '#') flag = true;
        if(buffer[i] == '*') break;
        if(flag){
            mbuf[pmbuf] = buffer[i];
            pmbuf++;
        }
    }
    std::cout << mbuf << std::endl;*/
    //std::cout << buffer;
}

int main()
{
    cssl_start();
    cssl_t *st = cssl_open("/dev/ttyACM0", cb, 0, 115200, 8, 0, 0);
    uint8_t * mbuf = new uint8_t[255];
    while (1)
    {
        cssl_putchar(st, '#');
        //sleep(100);
        //read(st->fd, mbuf, 51);
        std::cout << "read: " << cssl_getchar(st) << std::endl;
        //cssl_drain(st);
    }
}